package com.dhcc.utils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.ServletRequest;

public class __ServletRequest {
	private static final Map<String, String> map;
	private static final Map<String, Operator<ServletRequest>> operators;
	static{
		map = UtilUtil.scan("com.dhcc.utils.servletrequest");
		operators = new ConcurrentHashMap<String, Operator<ServletRequest>>(map.size());
	}
	/**
	 * 执行servletrequest的操作
	 * @param operator
	 * @param servletRequest
	 * @param args
	 * @return
	 */
	public static <T> T op(String operator, ServletRequest servletRequest, Object... args){
		return UtilUtil.<T, ServletRequest>op(map, operators, operator, servletRequest, args);
	}
	
	public static void registry(String name, Class<? extends Operator<ServletRequest>> clazz){
		UtilUtil.<ServletRequest>registry(name, clazz, map);
	}
	
	/**
	 * 获取客户端ip地址
	 * @param servletRequest
	 * @return
	 */
	public static String ip(ServletRequest servletRequest){
		return op("ip", servletRequest);
	}
}
